package it.softphone.commons.service.security;

import it.softphone.commons.exception.NullParameterException;

public class SecurityAccountServiceUtil {

	
	protected SecurityAccountServiceUtil() {
	}

	public static boolean hasOneOfRole( SecurityAccountService service, java.util.Collection<String> roles ) {
		if( roles==null ) throw new NullParameterException( "roles");
		if( service==null ) throw new NullParameterException( "service");
		
		boolean [] result = service.hasRoles(roles);
		
		boolean ret = false;
		
		for( boolean b : result ) { 
			if( b ) {
				ret = true ;
				break;
			}
		}
		
		return ret;
		
	}
		
	public static boolean isPermittedOneOf(  SecurityAccountService service, java.util.Collection<String> permissions ) {
		if( permissions==null ) throw new NullParameterException( "permissions");
		if( service==null ) throw new NullParameterException( "service");
			
		boolean [] result = service.isPermitted( permissions );

		boolean ret = false;
		
		for( boolean b : result ) { 
			if( b ) {
				ret = true ;
				break;
			}
		}
		
		return ret;
		
	}
	
}
